package com.example.myapplication.adapter.recyclerViewAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.entity.Desc;

import java.util.List;

public class SongDescAdapter extends RecyclerView.Adapter<SongDescAdapter.DescHolder> {

    private List<Desc.IntroductionBean>introductionBeanList;
    private Desc desc;
    private Context context;

    public SongDescAdapter(Context context) {
        this.context = context;
    }

    public void setData(Desc desc){
        this.desc = desc;
        this.introductionBeanList = desc.getIntroduction();
        notifyDataSetChanged();
    }
    @NonNull
    @Override
    public DescHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_desc,parent,false);
        return new DescHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull DescHolder holder, int position) {
         Desc.IntroductionBean introductionBean = introductionBeanList.get(position);
         if(position==0){
             holder.ti.setText("歌手资料");
             holder.txt.setText(desc.getBriefDesc());
         }
         else {
             holder.ti.setText(introductionBean.getTi());
             holder.txt.setText(introductionBean.getTxt());
         }
    }

    @Override
    public int getItemCount() {
        return introductionBeanList==null? 0 : introductionBeanList.size();
    }

    class DescHolder extends RecyclerView.ViewHolder{
        TextView ti;
        TextView txt;
        public DescHolder(@NonNull View itemView) {
            super(itemView);
            ti=itemView.findViewById(R.id.ti);
            txt=itemView.findViewById(R.id.txt);
        }
    }
}
